<?php

namespace app\admin\controller;

use app\admin\controller\CommonController;
use app\admin\model\Enterprise;
use app\util\Util;

/*
 * 关于我们
 */
class EnterpriseController extends CommonController
{
    /*
     * 关于我们
     */
    public function about()
    {
        $row = Enterprise::where('id', '=', Enterprise::ID_1)->find();

        return view('about', [
            'row' => $row
        ]);
    }

    /*
     * 联系我们
     */
    public function contact()
    {
        $row = Enterprise::where('id', '=', Enterprise::ID_2)->find();

        return view('contact', [
            'row' => $row
        ]);
    }

    /*
     * 商务合作
     */
    public function cooperate()
    {
        $row = Enterprise::where('id', '=', Enterprise::ID_3)->find();

        return view('cooperate', [
            'row' => $row
        ]);
    }

    /*
     * 加入我们
     */
    public function joinus()
    {
        $row = Enterprise::where('id', '=', Enterprise::ID_4)->find();

        return view('joinus', [
            'row' => $row
        ]);
    }

    /*
     * 免责声明
     */
    public function statement()
    {
        $row = Enterprise::where('id', '=', Enterprise::ID_5)->find();

        return view('statement', [
            'row' => $row
        ]);
    }

    /*
     * 建议与投诉
     */
    public function suggest()
    {
        $row = Enterprise::where('id', '=', Enterprise::ID_6)->find();

        return view('suggest', [
            'row' => $row
        ]);
    }

    /*
     * 保存
     * 关于我们
     * 联系我们
     * 商务合作
     * 加入我们
     * 免责声明
     * 建议与投诉
     */
    public function postAbout()
    {
        $id = input('post.id');
        $title = input('post.title');
        $content = input('post.content');

        $data = [
            'title' => $title,
            'content' => $content,
        ];

        $row = Enterprise::where('id', '=', $id)->find();
        $result = false;
        if (is_null($row)) {
            $data['add_time'] = time();

            $result = Enterprise::insert($data);
        } else {
            $result = Enterprise::where('id', '=', $id)->update($data);
        }

        if ($result) {
            return Util::ajaxReturn(1, '保存成功', null);
        } else {
            return Util::ajaxReturn(0, '保存失败', null);
        }
    }

}